import absevnt from '../../abseventsvc.js'
import rightmenumainaction from '../RMouseAction/rightmenumainaction.js'
import utilfuncs from '../../../canvas/common/tools/utilfuncs.js';
var funcs = utilfuncs.UtilFuncs;

class XMindRMosUpSelGraphSvc extends absevnt.IEventSvc {
    constructor() {
        super();
    }
    act(canvasEvt) {
        console.log("XMindRMosUpSelGraphSvc:xxx---------");
        let clickRightHtml = document.getElementsByClassName('clickRightMenu')[0];

        while (clickRightHtml.firstChild) {
            clickRightHtml.removeChild(clickRightHtml.lastChild);
        }

        this.createRMenu(clickRightHtml, canvasEvt);
        clickRightHtml.style.display = "block";
        clickRightHtml.style.left = canvasEvt.scrnx + "px";
        clickRightHtml.style.top = canvasEvt.scrny + "px";
        window.mainctl.forbidMouseMove = true;
    }

    createRMenu(clickRightHtml, canvasEvt) {
        this.addItem(clickRightHtml, "insertTheme","插入主题");
        this.addItem(clickRightHtml, "insertSubTheme","插入子主题");
        this.addItem(clickRightHtml, "delete","删除");
        this.addItem(clickRightHtml, "copy","复制");
        this.addItem(clickRightHtml, "paste","粘贴");
        if (!canvasEvt.lock) {
            this.addItem(clickRightHtml, "lock","锁定");
        }
        else {
            this.addItem(clickRightHtml, "unlock","解锁");
        }
        this.addItem(clickRightHtml, "editprop","属性样式");
        this.addItem(clickRightHtml, "xlink","链接");
    }

    addItem(clickRightHtml, subItem,title) {
        let editpropItem = document.getElementById(subItem);
        if (!editpropItem) {
            editpropItem = document.createElement('li');
            clickRightHtml.appendChild(editpropItem);
            editpropItem.id = subItem;
            editpropItem.innerHTML = title;

            editpropItem.addEventListener('click', function (evt) {
                clickRightHtml.style.display = "none";
                rightmenumainaction.RightMenuMainAction.act2Click(window.mainctl, evt, subItem);
                window.mainctl.forbidMouseMove = false;
            });
        }

        if (!window.mainctl.m_pRMenuINTF.chkItemCanDis(subItem)){
            clickRightHtml.removeChild(editpropItem);
            editpropItem = null;
        }
        return editpropItem;
    }

    addInsertSubItem(mainMenuItem, canvasEvt) {
        const submenu = document.createElement('div');
        mainMenuItem.appendChild(submenu);
        const submenuList = document.createElement('ul');
        const subItem1 = document.createElement('li');
            subItem1.textContent = 'Sub Item 1';
            submenuList.appendChild(subItem1);

            const subItem2 = document.createElement('li');
            subItem2.textContent = 'Sub Item 2';
            submenuList.appendChild(subItem2);

            const subItem3 = document.createElement('li');
            subItem3.textContent = 'Sub Item 3';
            submenuList.appendChild(subItem3);
            mainMenuItem.appendChild(submenuList);
        
        // this.addItem(submenuList, "theme","主题（Enter）");
        // this.addItem(submenuList, "subTheme","子主题（inert）");
    }
}

export  { XMindRMosUpSelGraphSvc }